	//Use main data
	use "${maindta}", clear
	
	collapse (p90) p90=firm_score_est (p10) p10=firm_score_est (p75) p75=firm_score_est (p25) p25=firm_score_est (sd) sd=firm_score_est [aw=wt], by(country)
	gen _90to10 = p90/p10 
	gen _75to25 = p75/p25 
	
	gen _90min10 = p90 - p10 
	gen _75min25 = p75 - p25 
	
	mean _90* _75*
	
	matrix table=r(table)
	matrix list table 
	
	//10 to 90 range 
	loc 1  = table[1,2]
	loc 1  = string(`1', "%9.1f")
	di "`1'"
	
	//10 to 90 ratio 
	loc 2  = table[1,1]
	loc 2  = string(`2', "%9.1f")
	di "`2'"
	
	//25 to 75 range 
	loc 3  = table[1,4]
	loc 3  = string(`3', "%9.1f")
	di "`3'"

	//25 to 75 ratio 
	loc 4  = table[1,3]
	loc 4  = string(`4', "%9.1f")
	di "`4'"
	
	//SD
	su sd
	local 5 = string(`r(mean)', "%9.1f")
	di "`5'"
	
	gen table4=""
	replace table4 = " & 10th to 90th Range & 10th & 90th Ratio & 25th to 75th Range & 25th to 75th Ratio & S.D." in 1 
	replace table4 = " & `1' & `2' & `3' & `4' & `5'" in 2 
	
	export delimited table4 using "${outtables}\\table4.txt", nolabel noquote replace